﻿<m:EntityListBase
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:m="clr-namespace:Signum.Windows"
    x:Class="Signum.Windows.EntityRepeater"
	x:Name="me"  MinWidth="200" >
    <m:EntityListBase.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Resources.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <Style x:Key="RepeaterItemStyle" TargetType="{x:Type ContentControl}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ContentControl}">
                            <m:EntityRepeaterLineBorder BorderBrush="{DynamicResource LightBlue}" BorderThickness="1" Padding="1" m:Common.TypeContext="{m:ContinueRoute /}">
                                <Grid Loaded="Grid_Loaded" >
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition  Width="*"/>
                                        <ColumnDefinition  Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <ContentPresenter 
						                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
						                HorizontalAlignment="Stretch"  />
                                    <Button x:Name="btRemove" Click="btRemove_Click" 
                                        Style="{StaticResource RoundButton}" 
                                        Content="{StaticResource Remove}" 
                                        ToolTip="{m:Loc Remove}"
                                        HorizontalAlignment="Right"
                                        VerticalAlignment="Top"
                                        Loaded="btRemove_Loaded"
                                        Grid.Column="1"/>
                                </Grid>
                            </m:EntityRepeaterLineBorder>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </m:EntityListBase.Resources>

    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="25"/>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid Background="{DynamicResource LightBlueBackground}">
            <StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
                <Image Stretch="None" Source="{Binding Icon, ElementName=me, Mode=Default}" SnapsToDevicePixels="True" RenderOptions.BitmapScalingMode="NearestNeighbor" />
                <Label Content="{Binding LabelText, ElementName=me, Mode=Default}" VerticalAlignment="Center" />
            </StackPanel>
            <StackPanel HorizontalAlignment="Right" Margin="0,1.5" Orientation="Horizontal">
                <Button x:Name="btCreate" Click="btCreate_Click" Style="{StaticResource RoundButton}" ToolTip="{m:Loc Create}"   
                        Content="{StaticResource Create}"/>
                <Button x:Name="btFind" Click="btFind_Click" Style="{StaticResource RoundButton}" ToolTip="{m:Loc Find}"   
                        Content="{StaticResource Find}"/>
            </StackPanel>
        </Grid>
        <ScrollViewer x:Name="ScrollViewer"
                      VerticalScrollBarVisibility="{Binding VerticalScrollBarVisibility, ElementName=me}"
                      HorizontalScrollBarVisibility="{Binding HorizontalScrollBarVisibility, ElementName=me}" Grid.Row="1" >
            <m:RepeaterItemsControl  x:Name="itemsControl"
			ItemsSource="{Binding Entities, ElementName=me, Mode=Default}" 
			ItemTemplate="{Binding EntityTemplate, ElementName=me, Mode=Default}" 
			ItemContainerStyle="{DynamicResource RepeaterItemStyle}"
            HorizontalContentAlignment="Stretch"
			HorizontalAlignment="Stretch" 
            VerticalAlignment="Stretch" />
        </ScrollViewer>
    </Grid>
</m:EntityListBase>